<?php
/*
	Class from http://stackoverflow.com/questions/1694136/zend-form-add-error-message
	
	You have to add the namespace Perso_ to the application.ini to make it works
*/
class Perso_Validate_ElementConfirmation extends Zend_Validate_Abstract
{
    const NOT_MATCH = 'notMatch';

	// Message to display if there is an error
    protected $_messageTemplates = array(
        self::NOT_MATCH => 'Password confirmation does not match'
    );
    
	protected $_context;
    
    public function __construct($context)
    {
        $this->_context = $context;
    }

	// Function check
    public function isValid($value, $context = null)
    {
    	// Hold the original field
        $value = (string) $value;
        $this->_setValue($value);
		
        if (is_array($context)) {
            if (isset($context[$this->_context])
                && ($value == $context[$this->_context]))
            {
                return true;
            }
        } else if (is_string($context) && ($value == $context)) {
            return true;
        }

        $this->_error(self::NOT_MATCH);
        return false;
    }
}
